package com.my.xinyidaixi.Fragment;

import android.app.Fragment;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.my.xinyidaixi.Activity.add_address;
import com.my.xinyidaixi.Activity.chongzhi;
import com.my.xinyidaixi.Activity.feedback;
import com.my.xinyidaixi.Activity.gengduo;
import com.my.xinyidaixi.Activity.login_activity;
import com.my.xinyidaixi.Activity.my_integral;
import com.my.xinyidaixi.Activity.my_overage;
import com.my.xinyidaixi.Activity.my_youhuiquan;
import com.my.xinyidaixi.DataBase.Model.Over_UserModer;
import com.my.xinyidaixi.DataBase.Model.UserModel;
import com.my.xinyidaixi.Globe.MyApplication;
import com.my.xinyidaixi.R;
import com.my.xinyidaixi.Util.ToastUtil;

/**
 * Created by zw on 2017/6/1.
 */
public class Mine_Fragment extends Fragment {

    private Context context= MyApplication.getInstance();
    private View fragment_3;
    private Intent intent;
    private LinearLayout mine_login;
    private UserModel model=new Over_UserModer();
    private RelativeLayout gengduo_button;
    private TextView login_text_1,login_text_2,point,overage,ticket;
    private LinearLayout overage_button,integral_button,youhuiquan_button;
    private TextView mine_chongzhi;
    private RelativeLayout feed_back;
    private RelativeLayout changyongdizhi;
    private RelativeLayout jifenshangcheng;
    private RelativeLayout tuijianyoujiang;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        fragment_3 = inflater.inflate(R.layout.mine,container,false);
        initdata();
        return fragment_3;
    }

    @Override
    public void onResume() {
        super.onResume();
        if(model.count()>0)
        {
            login_text_1.setText(model.getUser());
            point.setText(model.getpoint());
            overage.setText("￥"+model.getmoney());
            ticket.setText(model.getticket()+"张");
            mine_login.setEnabled(false);
        }
        else
        {
            login_text_1.setText("登录");
            mine_login.setEnabled(true);
            point.setText("0");
            overage.setText("￥0.00");
            ticket.setText("0张");
        }
    }

    public void initdata()
    {
        gengduo_button = (RelativeLayout) fragment_3.findViewById(R.id.gengduo_relativelayout_button);
        gengduo_button.setOnClickListener(new button());
        mine_login = (LinearLayout) fragment_3.findViewById(R.id.mine_login);
        mine_login.setOnClickListener(new button());
        login_text_1 = (TextView) fragment_3.findViewById(R.id.mine_login_text_1);
        //login_text_2 = (TextView) fragment_3.findViewById(R.id.mine_login_text_2);

        overage_button = (LinearLayout) fragment_3.findViewById(R.id.mine_my__overage_button);
        overage_button.setOnClickListener(new button());
        integral_button = (LinearLayout) fragment_3.findViewById(R.id.mine_my_integral_button);
        integral_button.setOnClickListener(new button());
        youhuiquan_button = (LinearLayout) fragment_3.findViewById(R.id.mine_my_youhuiquan_button);
        youhuiquan_button.setOnClickListener(new button());

        mine_chongzhi = (TextView) fragment_3.findViewById(R.id.mine_chongzhi);

        mine_chongzhi.setOnClickListener(new button());


        point = (TextView) fragment_3.findViewById(R.id.mine_point);
        overage = (TextView) fragment_3.findViewById(R.id.mine_overage);
        ticket = (TextView) fragment_3.findViewById(R.id.mine_ticket);

        feed_back = (RelativeLayout) fragment_3.findViewById(R.id.mine_feedback);
        feed_back.setOnClickListener(new button());
        changyongdizhi = (RelativeLayout) fragment_3.findViewById(R.id.mine_changyongdizhi);
        changyongdizhi.setOnClickListener(new button());
        jifenshangcheng = (RelativeLayout) fragment_3.findViewById(R.id.mine_jifenshangcheng);
        jifenshangcheng.setOnClickListener(new button());
        tuijianyoujiang = (RelativeLayout) fragment_3.findViewById(R.id.mine_tuijianyoujiang);
        tuijianyoujiang.setOnClickListener(new button());
    }

    public class button implements View.OnClickListener
    {
        @Override
        public void onClick(View v)
        {

            switch (v.getId())
            {
                case R.id.gengduo_relativelayout_button:
                    intent=new Intent();
                    intent.setClass(context, gengduo.class);
                    startActivity(intent);
                    getActivity().overridePendingTransition(R.anim.ani_right_get_into,R.anim.ani_left_sign_out);
                    break;
                case R.id.mine_login:
                    intent=new Intent();
                    intent.setClass(context,login_activity.class);
                    startActivity(intent);
                    getActivity().overridePendingTransition(R.anim.ani_right_get_into,R.anim.ani_left_sign_out);
                    break;
                case R.id.mine_my__overage_button:
                    if(model.count()==0)
                    {
                        ToastUtil.shortToast(context,"请先登录");
                        return;
                    }
                    intent=new Intent();
                    intent.setClass(context,my_overage.class);
                    startActivity(intent);
                    getActivity().overridePendingTransition(R.anim.ani_right_get_into,R.anim.ani_left_sign_out);
                    break;
                case R.id.mine_my_integral_button:
                    if(model.count()==0)
                    {
                        ToastUtil.shortToast(context,"请先登录");
                        return;
                    }
                    intent=new Intent();
                    intent.setClass(context,my_integral.class);
                    startActivity(intent);
                    getActivity().overridePendingTransition(R.anim.ani_right_get_into,R.anim.ani_left_sign_out);
                    break;
                case R.id.mine_my_youhuiquan_button:
                    if(model.count()==0)
                    {
                        ToastUtil.shortToast(context,"请先登录");
                        return;
                    }
                    intent=new Intent();
                    intent.setClass(context,my_youhuiquan.class);
                    startActivity(intent);
                    getActivity().overridePendingTransition(R.anim.ani_right_get_into,R.anim.ani_left_sign_out);
                    break;
                case R.id.mine_chongzhi:
                    if(model.count()==0)
                    {
                        ToastUtil.shortToast(context,"请先登录");
                        return;
                    }
                    intent=new Intent();
                    intent.setClass(context,chongzhi.class);
                    startActivity(intent);
                    getActivity().overridePendingTransition(R.anim.ani_right_get_into,R.anim.ani_left_sign_out);
                    break;

                case R.id.mine_feedback:
                    intent=new Intent();
                    intent.setClass(context,feedback.class);
                    startActivity(intent);
                    getActivity().overridePendingTransition(R.anim.ani_right_get_into,R.anim.ani_left_sign_out);
                    break;
                case R.id.mine_changyongdizhi:
                    if(model.count()==0)
                    {
                        ToastUtil.shortToast(context,"请先登录");
                        return;
                    }
                    intent=new Intent();
                    intent.setClass(context, add_address.class);
                    intent.putExtra("boolean",true);
                    startActivity(intent);
                    getActivity().overridePendingTransition(R.anim.ani_right_get_into,R.anim.ani_left_sign_out);
                    break;
                case R.id.mine_jifenshangcheng:
                    ToastUtil.shortToast(context,"功能暂未开放");
                    break;
                case R.id.mine_tuijianyoujiang:
                    ToastUtil.shortToast(context,"功能暂未开放");
                    break;
            }
        }
    }
}
